package com.bw.goods.mvvm.bind;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bw.goods.R;
import com.bw.goods.mvvm.model.entity.Listdetail;
import com.bw.goods.mvvm.viewmodel.HomeValuesViewmodel;
import com.bw.mvvm_common.BaseApplication;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

public
/**
 * @author Lishaohe
 * @description:
 * @date :2021/10/21 0021 下午 3:07
 *
 */
class DetailBind {
    @BindingAdapter(value = {"detailadapter","img","title","money","detail"})
    public static void details(
            RecyclerView recyclerView,
            BaseQuickAdapter adapter,
            String img ,
            String title ,
            int money ,
            String detail

    ){
//        LinearLayoutManager manager = new LinearLayoutManager(recyclerView.getContext());
        GridLayoutManager manager = new GridLayoutManager(recyclerView.getContext(), 2);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        BaseQuickAdapter adapter1 = (BaseQuickAdapter) recyclerView.getAdapter();
        if (adapter1==null){

            View inflate = LayoutInflater.from(recyclerView.getContext()).inflate(R.layout.view_homevalue, null);

            ImageView imageView = inflate.findViewById(R.id.value_head_img);
            Glide.with(BaseApplication.getApplication()).load(img).into(imageView);

            TextView title1 = inflate.findViewById(R.id.value_head_title);
            title1.setText(title);

            TextView money1 = inflate.findViewById(R.id.detailtitle);
            money1.setText("￥"+money);

            TextView textView2 = inflate.findViewById(R.id.mSkuSelectedTv);
            textView2.setText(detail);


            adapter.addHeaderView(inflate);
        }else {
            LinearLayout headerLayout = adapter.getHeaderLayout();
            ImageView imageView = headerLayout.findViewById(R.id.value_head_img);
            Glide.with(BaseApplication.getApplication()).load(img).into(imageView);

            TextView title1 = headerLayout.findViewById(R.id.value_head_title);
            title1.setText(title);

            TextView money1 = headerLayout.findViewById(R.id.detailtitle);
            money1.setText("￥"+money);

            TextView textView2 = headerLayout.findViewById(R.id.mSkuSelectedTv);
            textView2.setText(detail);
        }

        recyclerView.setAdapter(adapter);
    }
}
